
package org.jdcenter.jndi.context.remote;

import java.util.concurrent.ConcurrentHashMap;

import javax.naming.Context;
import javax.naming.NamingException;

import org.jdcenter.jndi.context.ProxyContext;
/**
 * @author miao
 * 远程Context代理
 * 
 */

public class RemoteProxyContext extends ProxyContext {
    
	private String ip = "127.0.0.1";
	private int port = 1099;
    private String subContextName = "org.jdstream.jndi.context.local.RMIJRMPContextClient";
    
    
    private static ConcurrentHashMap<String,Context> contexts 
    		= new ConcurrentHashMap<String,Context>();
    
    public RemoteProxyContext(String address) throws NamingException{
    	String[] adrs = address.split(":");
    	this.ip = adrs[0];
    	this.port = Integer.parseInt(adrs[1]);
    	init();
    	delegateContext = stubContext;
    }

    protected String getStubContextName(){
    	return subContextName;
    }
    public static Context getContext(String address) throws NamingException{
    	Context context = contexts.get(address);
    	if(context == null){
    		context = new RemoteProxyContext(address);
    		contexts.put(address, context);
    	}
    	return context;
    }
    

}
